package br.usp.ime.mac.mico.acceptance.tests;

import br.usp.ime.mac.mico.dao.JPASampleDAO;
import br.usp.ime.mac.mico.factories.JPADAOFactory;
import br.usp.ime.mac.mico.models.Sample;
import junit.framework.TestCase;

//The acceptance test for card numer 1, Samples.
public class SamplesAcceptanceTest extends TestCase {

	private Sample sampleA;
	private Sample sampleB;
	private Sample sampleC;
	private String sampleALocalCode = "S.A.M.P.L.E. - A";
	private String sampleBLocalCode = "S.A.M.P.L.E. - B";
	private String sampleCLocalCode = "S.A.M.P.L.E. - C";
	private String[] sampleLCError  = {"", null};
	private JPASampleDAO sampleDAO;//  = JPADAOFactory.getSampleDAO();

	@Override
	public void setUp() {
		sampleA = new Sample();
		//sampleB = new Sample(sampleBLocalCode);
		sampleC = new Sample();
		sampleA.setLocalCode(sampleBLocalCode);
		sampleC.setLocalCode(sampleCLocalCode);
	}

	public void testSampleLocalCode() {
		assertEquals(sampleA.getLocalCode(), sampleALocalCode);
		assertEquals(sampleB.getLocalCode(), sampleBLocalCode);

		sampleDAO.openPersistence();
		long sampleAID = sampleDAO.salvar(sampleA);
		long sampleBID = sampleDAO.salvar(sampleB);
		sampleDAO.closePersistence();
		sampleDAO.openPersistence();
		assertEquals(sampleALocalCode, sampleDAO.buscaPorId(sampleAID));
		assertEquals(sampleALocalCode, sampleDAO.buscaPorId(sampleAID));

		sampleA.setLocalCode(sampleCLocalCode);
		sampleDAO.atualizar(sampleA);
		assertEquals(sampleCLocalCode, sampleDAO.buscaPorId(sampleAID));

		try{
			sampleDAO.salvar(sampleC);
			fail();
		}
		catch (Exception e) {}

		for (int i = 0; i < sampleLCError.length; i++) {
			sampleC.setLocalCode(sampleLCError[i]);
//			assertFalse(sampleC.isValid());
			try{
				sampleDAO.salvar(sampleC);
				fail();
			}
			catch (Exception e) {}
		}
	}

	public void testSampleOriginalCode() {
		
	}
}
